﻿package tools;

import java.io.File;

/**
 * 将2个行数一样的文件合并成一个文件
 * 
 * @author BlueJade
 * @version 1.0
 */
public class FileCombine {
	public static void combine(String file1, String file2, String outputfile, String separation) {
		String file1Content = FileReaderEnhance.readToString(new File(file1));
		String file2Content = FileReaderEnhance.readToString(new File(file2));
		StringBuilder sb = new StringBuilder();
		
		String[] contents1 = file1Content.split("\n");
		String[] contents2 = file2Content.split("\n");
		
		if (contents1.length != contents2.length) {
			System.err.println("The line number of file1 and file2 is not equal!");
			System.exit(1);
		}
		
		for (int i = 0; i < contents1.length; i++) {
			sb.append(contents1[i] + separation + contents2[i]);
			sb.append("\n");
		}
		
		FileWriterEnhance fw = new FileWriterEnhance(outputfile);
		fw.WriteToFile(sb.toString());
	}
}
